package models
{
	import mx.collections.ArrayCollection;
	
	public class Entry
	{
		public var start:Date;
		public var end:Date;
		public var startAmbiguity:Number;
		public var endAmbiguity:Number;
		public var password:String = '';
		public var title:String = '';
		public var description:String = '';
		public var files:Array = new Array();
		private var _category:String = '';
		private static var _used_categories:Object = {};
		public function get category():String { return _category; }
		public function set category(c:String):void { 
			_category = c;
			
			if(!_used_categories[c]) {
				
				_used_categories[c] = true;
				getCategories().addItem(c);
				
			}				
		}		
			
		public static var categories:ArrayCollection = null;	
				
		public function Entry(s:Date, e:Date, t:String, d:String = '', sa:Number = 0, ea:Number = 0, pswd:String = '',  f:Array = null, c:String = '')
		{

			start = s;
			end = e;
			startAmbiguity = sa;
			endAmbiguity = ea;
			password = pswd;
			title = t;

			description = d;
			files = f;
			
			if(c != '')
			{
				if(!categories.contains(new String(c)))
				{
					categories.addItem(new String(c));
				}
			}

		}
		
		public function equal_entry(s:Date, e:Date, t:String, d:String, sa:Number, ea:Number, pswd:String,  f:Array, c:String):Boolean
		{
			if ((start==s) && (end==e) && (startAmbiguity==sa) && (endAmbiguity==ea) && (password==pswd) && (files == f) && (category == c) )
				return true;
			else return false;
		}

		public function setTitle(t:String):void
		{
			this.title = t;
		}
		
		public function setCategory(c:String):void
		{
			if(c!=="")
			{
				if(!categories.contains(c))
				{
					categories.addItem(c);
				}
			
				this.category=c;
			}
		}
		
		public function getStart():Number
		{
			return this.start.time;
		}

		
		public static function getCategories():ArrayCollection
		{
			if(categories==null)
			{

				categories = new ArrayCollection();				

			}
			return categories;
		}

	}
}